﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Reflection;

namespace SkyBase
{
    /// <summary>
    /// A static class for Debugging the game.
    /// </summary>
    static class Debugger
    {
        private static List<string> toDebug = new List<string>();


        /// <summary>
        /// If class is enabled, print string
        /// </summary>
        /// <param name="input">String to print</param>
        public static void writeLine(string input)
        {

            StackTrace stackTrace = new StackTrace();
            MethodBase methodBase = stackTrace.GetFrame(1).GetMethod();
            if(toDebug.Contains(methodBase.ReflectedType.Name))
                Debug.WriteLine("[" + DateTime.Now + "] [DEBUG] [" + methodBase.ReflectedType.Name + "." + methodBase.Name + "] " + input);
         
        }

        /// <summary>
        /// Print string for debug purposes.
        /// </summary>
        /// <param name="input">String to print</param>
        public static void debug(string input)
        {
            StackTrace stackTrace = new StackTrace();
            MethodBase methodBase = stackTrace.GetFrame(1).GetMethod();
            Debug.WriteLine("[" + DateTime.Now + "] [DEBUG] [" + methodBase.ReflectedType.Name + "." + methodBase.Name + "] " + input);
        }

        /// <summary>
        /// Enable debug printing for current class.
        /// </summary>
        public static bool enabled
        {
            get
            {
                StackTrace stackTrace = new StackTrace();
                MethodBase methodBase = stackTrace.GetFrame(1).GetMethod();
                return toDebug.Contains(methodBase.ReflectedType.Name);
            }
            set
            {
                StackTrace stackTrace = new StackTrace();
                MethodBase methodBase = stackTrace.GetFrame(1).GetMethod();
                
                if(value)
                    toDebug.Add(methodBase.ReflectedType.Name);
                else
                    if(toDebug.Contains(methodBase.ReflectedType.Name))
                        toDebug.Remove(methodBase.ReflectedType.Name);
            }
        }

        
    }
}
